package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.SupplierDao;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: jxc
 * @description:
 * @author: SXC
 * @create: 2021-09-04 11:39
 **/
@Service
public class SupplierServiceImpl implements SupplierService {
    @Autowired
    private SupplierDao supplierDao;

    /**
     * 获取数据
     * @param page
     * @param rows
     * @param supplierName
     * @return
     */
    @Override
    public List<Supplier> getSupplierList(Integer page, Integer rows, String supplierName) {
        page = page < 1 ? 0 : (page -1) * rows;
        rows = rows < 1 ? 10 : rows;
        return supplierDao.selectSupplierList(page,rows,supplierName);
    }

    /**
     * 获取条数
     * @return
     */
    @Override
    public int selectCount() {
        return supplierDao.selectCount();
    }

    /**
     * 供应商添加或修改
     * @param supplier
     */
    @Override
    public void saveOrUpdateSupplier(Supplier supplier) {
        if (supplier != null){
            if (supplier.getSupplierId() != null){
                //修改操作
                supplierDao.updateSupplier(supplier);
            }else {
                supplierDao.saveSupplier(supplier);
            }
        }
    }

    /**
     * 删除供应商（支持批量删除）
     * @param ids
     */
    @Override
    public void deleteList(String[] ids) {
        for (String ID: ids) {
            supplierDao.delete(ID);
        }
    }
}
